<template>
	<view class="content">
		<view class="con-head">童年造物</view>
		<view style="display: flex;align-items: center;width:100%;justify-content: space-around;">
			<view style="padding:0 5px 0 10px;text-align: center;" @click="openRoleDialog">
				{{roleList[tabIndex].name}}<uni-icons type="down" size="" color="#fff"></uni-icons>
			</view>
			<view style="padding:0 5px 0 10px;text-align: center;" @click="openDialog">
				音色选择<uni-icons type="down" size="" color="#fff"></uni-icons>
			</view>
		</view>
		<view :style="{height: contentViewHeight + 'px'}" class="mainCon">
			<image v-if="playStatus" src="../../static/assitant (2).gif"
				style="width:150px;height: 220px;margin: 10px 0 0 0;" mode="aspectFilt">
			</image>
			<image v-else src="../../static/logo.png" style="width:150px;height: 220px;margin: 10px 0 0 0;"
				mode="aspectFilt"></image>

			<view class="callBox">
				<image style="width: 50px;height: 50px;background-color: #413d3d;border-radius: 50px"
					src='../../static/audio/suspend.svg' v-if="!isRecording" @click="startDialog"></image>
				<image style="width: 50px;height: 50px;background-color: #413d3d;border-radius: 50px"
					src='../../static/audio/start.svg' v-if="pauseStatus" @click="stopDialog">
				</image>
				<view v-if="playStatus" @click="startDialog" class="offBtn">
					<view class="off"></view>
				</view>

				<view class="record-animate-box">
					<view class="voice-scale">
						<view :class="isRecording?'itemActive':'item'" v-for="(item,index) in 10" :key="index">
						</view>
					</view>
				</view>
				<image src="../../static/icon/text.png"
					style="width: 30px;height: 30px;background-color: #413d3d;border-radius: 50px;padding: 10px;"
					@click="toDetail"></image>
			</view>
			<!-- {{this.callbackMsg}} -->
		</view>

		<uni-popup ref="rolePopup" type="center" border-radius="10px" background-color="RGB(108, 104, 104, 0.69)">
			<view style="padding: 10px 10px 0;width: 150px;text-align: center;height: 220px;overflow: auto;">
				<view style="padding: 0 0 5px 0;color:#c5c5c5;">助理选择</view>
				<view v-for="(item,index) in roleList" :key="index" @click="selectRole(index)"
					style="padding:8px 0;border-top:0.5px solid #818181">{{item.name}}</view>
			</view>
		</uni-popup>

		<uni-popup ref="popup" type="center" border-radius="10px" background-color="RGB(108, 104, 104, 0.69)">
			<view style="padding: 10px 10px 0;width: 150px;text-align: center;height: 220px;overflow: auto;">
				<view style="padding: 0 0 5px 0;color:#c5c5c5;">音色选择</view>
				<view v-for="(item,index) in voiceList" :key="index" @click="selectVoice(index)"
					style="padding:8px 0;border-top:0.5px solid #818181">{{item.name}}</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	var AsrUniModule = uni.requireNativePlugin("AsrUniModule")
	const innerAudioContext = uni.createInnerAudioContext();
	import {
		genBaseSignature,
		genTtsSignature,
		shortTextToVoice,
		checkSpeechJob,
		convertSpeechToText,
		genTtsLongSignature,
		longTextToVoice,
		checkVoiceJob
	} from '../../utils/tencent.js'
	import {
		agentText,
		changeModel
	} from "../../utils/agentText.js"
	import {
		douAgentText,
		douTextToVoice
	} from "../../utils/doubaoAgent.js"
	// 以下路径需根据项目实际情况填写
	import {
		pathToBase64,
		base64ToPath
	} from '../../js_sdk/mmmm-image-tools/index.js'
	import permission from '../../js_sdk/wa-permission/permission.js'
	export default {
		data() {
			return {
				isRecording: false, //开始状态按钮是否展示
				params: { //语音识别参数
					EngineModelType: "16k_zh",
					ChannelNum: 1,
					ResTextFormat: 3,
					SourceType: 1,
					Data: ""
				},
				chatMsg: [],
				dialogue: [], //聊天记录
				audio: "", //合成语音音频
				text: "",
				genStatus: false,
				callbackMsg: "", //页面展示文本
				timeoutTimer: null, // 计时器计算是否超过时间没有声音输入回调
				playStatus: false, //停止播放按钮是否展示
				roleList: [{ // 智能体列表
						id: 101,
						name: "我的助理",
						roleId: "DYDYGNjEjf3P",
						token: "g3zN7vYQz7UczV5HldF9a0TmPPqpciUf"
					},
					{
						id: 102,
						name: "故事大王",
						roleId: "qaN9pxjLvSNy",
						token: "qlnNil8ngXukLqR7uRavSzpjK69RyZIi"
					},
					{
						id: 103,
						name: "诗词大师",
						roleId: "q8OYD2HSpHNy",
						token: "hqTDbdoMK0qwEpp2CMPk5Otw7e4IRDXF"
					}, {
						id: 104,
						name: "英语训练",
						roleId: "bot-20241121152454-npzrt",
						token: "878a62d9-286a-4550-bad2-fad2bd9426bc"
					}, {
						id: 105,
						name: "数学天才",
						roleId: "svlhxJKD0jHJ",
						token: "z2i3TzocjIqzKxyxeMANeJAQ9vk4qbav"
					},
					{
						id: 106,
						name: "粤语达人",
						roleId: "QOtnQFhXzit3",
						token: "xQvF7U4lnUyWzUiORt3eB2a0LMk1LaAE"
					},
					{
						id: 107,
						name: "百科问答",
						roleId: "eJOspNDvfjpv",
						token: "jddWJXpzQn2k1m7E9sUPu4ZkZD58qPi7"
					},
					{
						id: 108,
						name: "成语接龙",
						roleId: "d4E5dWuOXRfW",
						token: "dxfYNOuGiTif5Mx6lpiyUBJoRJ0H4cKb"
					},
					{
						id: 109,
						name: "辩论家",
						roleId: "v2o6Gmy4ISck",
						token: "hB20Ke7mIS2UvAwEGvqvXBLu21Nl7LAH"
					},{
						id: 110,
						name: "孔子",
						roleId: "pPG10z4SzI7y",
						token: "uVHKT5fuEVaUJ0euxgLG6qx0sur47geB"
					}

				],
				roleModel: {}, // 选中的智能体
				tabIndex: 0, //智能体索引
				voiceList: [{ //音色列表
						id: 301032,
						name: "默认小童"
					},
					{
						id: 1018,
						name: "男老师"
					}, {
						id: 301038,
						name: "女老师"
					}, {
						id: 101015,
						name: "男同学"
					}, {
						id: 601012,
						name: "女同学"
					}, {
						id: 101019,
						name: "粤语女生"
					}, {
						id: "volcano_tts",
						name: "英语女生"
					},
					{
						id: "volcano_tts",
						name: "智慧老者"
					}
				],
				voiceIndex: 2, //音色索引
				pauseStatus: false, // 停止录音状态是否展示
				contentViewHeight: 0
			};
		},
		created() {
			this.contentViewHeight = uni.getSystemInfoSync().windowHeight - 120
		},
		onLoad() {
			let self = this
			//音频播放器
			innerAudioContext.onPlay(() => {
				this.playStatus = true
				console.log('音频开始播放');
			});

			innerAudioContext.onError((res) => {
				this.playStatus = false
				console.error('音频播放错误:', res.errMsg);
			});
			innerAudioContext.onPause((res) => {
				this.playStatus = false
				this.callbackMsg = ""
				console.error('音频播放停止:', res);
			});

			innerAudioContext.onEnded((res) => {
				console.error('音频播放结束:', res);
				this.startRecognition()
			});
			this.selectRole(0) // 初始化智能体
			//android通讯
			this.getPermission() // 获取权限
			//监听回调
			plus.globalEvent.addEventListener("asrEvent", function(result) {
				self.getCallBackMsg(result)
			})
		},
		methods: {
			//获取语音识别sdk回调信息
			getCallBackMsg(e) {
				if (e.action == 'segment') { //返回的稳定识别信息
					this.callbackMsg = e.data.val
					this.$forceUpdate() //强制更新
					this.stopRecognition(e.data.val) //停止识别
					clearTimeout(this.timeoutTimer) //有回调，停止无输入计时器计时
				} else {

				}

			},

			//选择智能体
			async selectRole(i) {
				if (!this.isRecording) {
					if (innerAudioContext) {
						innerAudioContext.pause()
					}
					//获取对应智能体聊天记录
					if (i == 0) {
						this.dialogue = uni.getStorageSync('zhuli') || []
					} else if (i == 1) {
						this.dialogue = uni.getStorageSync('gushi') || []
					} else if (i == 2) {
						this.dialogue = uni.getStorageSync('shici') || []
					} else if (i == 3) {
						this.dialogue = uni.getStorageSync('yingyu') || []
					} else if (i == 4) {
						this.dialogue = uni.getStorageSync('shuxue') || []
					} else if (i == 5) {
						this.dialogue = uni.getStorageSync('yueyu') || []
					} else if (i == 6) {
						this.dialogue = uni.getStorageSync('baike') || []
					} else if (i == 7) {
						this.dialogue = uni.getStorageSync('chengyu') || []
					} else if (i == 8) {
						this.dialogue = uni.getStorageSync('bianlun') || []
					} else if (i == 9) {
						this.dialogue = uni.getStorageSync('kongzi') || []
					} else {
						this.dialogu = []
					}
					this.tabIndex = i
					this.roleModel = this.roleList[i]
					let res = await changeModel(this.roleModel) //切换智能体
				} else {
					uni.showToast({
						title: "老师思考中，请稍后~",
						duration: 2000,
						icon: "none"
					});
				}

				this.$refs.rolePopup.close()

			},
			//跳转聊天详情
			toDetail() {
				uni.navigateTo({
					url: "/pages/index/detail"
				});

			},
			//获取权限
			getPermission() {
				AsrUniModule.requestPermissions()
			},
			//开始对话
			async startDialog() {
				let result = await permission.requestAndroidPermission('android.permission.RECORD_AUDIO')
				if (result == 1) {
					this.startRecognition() //通用权限，开始录音识别
				} else {
					uni.showToast({
						title: "该功能需要打开麦克风权限，请在设置中打开",
						duration: 3000,
						icon: "none"
					});
				}

			},
			//结束对话
			stopDialog() {
				this.isRecording = false
				this.pauseStatus = false
				this.playStatus = false
				AsrUniModule.stopAsr()
				if (this.timeoutTimer) {
					clearTimeout(this.timeoutTimer)
				}
			},
			// 开始识别的方法  
			startRecognition() {
				if (innerAudioContext) {
					innerAudioContext.pause()
				}
				this.pauseStatus = true
				this.isRecording = true
				AsrUniModule.startAsr()
				//计时器计算是否超过30s没有语音输入识别的回调，超过停止识别录音
				this.timeoutTimer = setTimeout(() => {
					this.isRecording = false
					this.pauseStatus = false
					this.playStatus = false
					this.callbackMsg = ""
					AsrUniModule.stopAsr()
					clearTimeout(this.timeoutTimer)
				}, 30000);
			},
			// 停止识别的方法  
			stopRecognition(e) {
				this.pauseStatus = false
				AsrUniModule.stopAsr()
				if (this.callbackMsg && this.callbackMsg.length !== 0) {
					let con = {
						role: "user",
						content: [{
							type: "text",
							text: this.callbackMsg
						}]
					}
					this.chatMsg.push(con) // 文本内容
					this.dialogue.push(con)
					//发送智能体
					this.sendAgent(e)
				} else {
					uni.showToast({
						title: "没有执行",
						duration: 3000,
						icon: "none"
					});
				}
			},
			//音频转base64
			convertToBase64(audioBlob) {
				let that = this
				plus.io.resolveLocalFileSystemURL(audioBlob, function(entry) {
					entry.file(
						function(file) {
							let reader = new plus.io.FileReader();
							reader.onloadend = function(e) {
								that.params.Data = e.target.result.replace(/^data:audio\/mpeg;base64,/, '')
								that.submit()

							};
							reader.readAsDataURL(file);
						},
						function(e) {
							console.log("读写出现异常: " + e.message);
						}
					);
				});
			},
			//base64转bolb
			base64ToBlob(base64Data) {
				base64ToPath(base64Data)
					.then(path => {
						innerAudioContext.src = path;
						innerAudioContext.play();
					})
			},
			//音频转文字
			async submit() {
				// 获取签名
				let signature = await genBaseSignature(this.params)
				// 创建语音转文字任务
				let createConverTask = await convertSpeechToText(signature)
				if (!createConverTask.Response.Data.TaskId) {
					return
				} // 没有任务id则转换失败
				// 获取签名
				let checkSignature = await genBaseSignature({
					TaskId: createConverTask.Response.Data.TaskId
				})
				// 轮询接收任务状态
				this.pollTaskStatus(createConverTask.Response.Data.TaskId, checkSignature)
			},
			// 轮询函数  
			pollTaskStatus(taskId, checkSignature, interval = 2000) {
				let stopPolling = false;
				const poll = () => {
					checkSpeechJob(taskId, checkSignature)
						.then(result => {
							if (result.data.Response.Data.Status == 2 && result.data.Response.Data.ResultDetail !==
								null) {
								let con = {
									role: "user",
									content: [{
										type: "text",
										text: result.data.Response.Data.Result
									}]
								}
								this.chatMsg.push(con) // 文本内容
								this.dialogue.push(con)
								//发送智能体
								this.sendAgent(result.data.Response.Data.Result)
								stopPolling = true; // 停止轮询  
							} else if (result.data.Response.Data.Status == 3) {
								uni.showToast({
									title: result.data.ErrorMsg,
									duration: 2000,
									icon: "none"
								});

								stopPolling = true; // 停止轮询  

							} else if (result.data.Response.Data.Status == 2 && result.data.Response.Data
								.ResultDetail == null) {

								stopPolling = true; // 停止轮询  
							} else {
								console.log("轮询")
							}


						})
						.catch(error => {
							console.error('检查任务状态时发生错误:', error);
							stopPolling = true; // 停止轮询
						})
						.finally(() => {
							if (!stopPolling) {
								setTimeout(poll, interval); // 继续轮询  
							}
						});
				};
				// 开始轮询  
				poll();
			},
			// 长文本合成任务轮询函数
			async pollTextToVoiceTaskStatus(taskId, voiceSignature, interval = 2000) {
				return new Promise((resolve, reject) => {
					let stopPolling = false
					const poll = () => {
						checkVoiceJob(taskId, voiceSignature)
							.then(result => {
								// console.log("longresult", result)
								if (result.data.Response.Data.Status == 2 && result.data.Response.Data
									.ResultUrl !==
									null) {
									this.audio = result.data.Response.Data
										.ResultUrl
									stopPolling = true; // 停止轮询  
									resolve()
								} else if (result.data.Response.Data.Status == 3) {
									uni.showToast({
										title: result.data.ErrorMsg,
										duration: 2000,
										icon: "none"
									});
									this.audio =
										'data:audio/mp3;base64,//NkxAAAAANIAAAAAExBTUVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//NkxHwAAANIAAAAAFVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//NkxHwAAANIAAAAAFVVVVVVVVXwGhoAQLwNEKAzgzwtSAoP/ADOJsJD/AtgPeAOIApD/w9MaYEphqwm//w0wUsDY4DeAREL7//4CixNg0AswOMZgof//l0iYzZKDgD6EmMwT3///5OjNi4ywaDwbEELxVIOMn/////mhfKpeIIUCZFxicy4mPBbIIXDH/////NkxHwAAANIAUAAAP///yJjJmhuVS8QQcBmbj2eJ8xJocAsBuXC2eJ9gEAgEAgEIhMIgEAgEACwxyTMzWAgxLYviYBZehoQLXaIdMpENGLYNda6BQg0wMTikxniWAYAFCHJAeIX3C4MLkDIMeJIMKk6HLhkIByAFoH7B+oWVjjJM2UsQKOcQx1j7HwMeHqh//NkxP8mNDooAZSYAIzDIh5TpOx0xSW50NXB9A+cY0codhZRu6FDOHzNBhmzAkidGbFJjlDIFTVdTar1uqgOeUB6IIZojoHYRAmzArf39vofKJPkXIYVCdGbJggxIE+XxyC0Yk/rvbf+tPf/yKFYok+bkwdJUlyCDvJs+WyAFMiJsTiBNpftup///TVNp70q//NkxOk6HBKyX5mQApAJAjMr1wgJ00+TddjGikrmuylYpC3N+uBw5lTF27LmMdcFoUaleETS1McoE4iyS+gOWE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qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq//NkxHwAAANIAAAAAKqqqqqqqqpMQU1FMy4xMDCqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq//NkxHwAAANIAAAAAKqqqqqqqqpMQU1FMy4xMDCqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq//NkxHwAAANIAAAAAKqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq'
									stopPolling = true; // 停止轮询  
									resolve()
								} else {
									console.log("轮询")
								}
							})
							.catch(error => {
								console.error('检查任务状态时发生错误:', error);
								stopPolling = true; // 停止轮询
							})
							.finally(() => {
								if (!stopPolling) {
									setTimeout(poll, interval); // 继续轮询  
								}

							});
					};
					// 开始轮询  
					poll();
				})
			},
			// 发送给智能体
			async sendAgent(msg) {
				let res = {}
				if (this.tabIndex == 3) {
					res = await douAgentText(msg)
				} else {
					res = await agentText(msg)
				}
				if (res.choices[0].message.content) {
					let con = {
						role: 'assitant',
						content: [{
							type: "text",
							text: res.choices[0].message.content
						}]
					}
					this.chatMsg.push(con) // 文本内容
					this.dialogue.push(con)
					// 存缓存
					if (this.tabIndex == 0) {
						uni.setStorageSync(
							"zhuli",
							this.dialogue
						);
					} else if (this.tabIndex == 1) {
						uni.setStorageSync(
							"gushi",
							this.dialogue
						);
					} else if (this.tabIndex == 2) {
						uni.setStorageSync(
							"shici",
							this.dialogue
						);
					} else if (this.tabIndex == 3) {
						uni.setStorageSync(
							"yingyu",
							this.dialogue
						);
					} else if (this.tabIndex == 4) {
						uni.setStorageSync(
							"shuxue",
							this.dialogue
						);
					} else if (this.tabIndex == 5) {
						uni.setStorageSync(
							"yueyu",
							this.dialogue
						);
					} else if (this.tabIndex == 6) {
						uni.setStorageSync(
							"baike",
							this.dialogue
						);
					} else if (this.tabIndex == 7) {
						uni.setStorageSync(
							"chengyu",
							this.dialogue
						);
					} else if (this.tabIndex == 8) {
						uni.setStorageSync(
							"bianlun",
							this.dialogue
						);
					} else if (this.tabIndex == 9) {
						uni.setStorageSync(
							"kongzi",
							this.dialogue
						);
					}

					this.genStatus = false
					this.playVideo(res.choices[0].message.content)
				}
			},
			//合成语音
			async playVideo(text) {
				let voiceSignature = null
				let result = null
				let createVoiceTask = null
				if (this.voiceIndex == 6) {
					result = await douTextToVoice(text, 1)
					if (result.code == 3000) {
						this.audio = 'data:audio/mp3;base64,' + result.data
						this.base64ToBlob(this.audio)
					}
				} else if (this.voiceIndex == 7) {
					result = await douTextToVoice(text, 2)
					if (result.code == 3000) {
						this.audio = 'data:audio/mp3;base64,' + result.data
						this.base64ToBlob(this.audio)
					}
				} else {
					// 判断字符数是否超过150  
					if (text.length < 150) {
						console.log("短文本");
						let msg = {
							Text: text,
							SessionId: "1234",
							Codec: "mp3",
							VoiceType: this.voiceList[this.voiceIndex].id,
							EmotionCategory: 'exciting'
						}
						// 签名
						voiceSignature = await genTtsSignature(msg)
						result = await shortTextToVoice(msg, voiceSignature)
						if (result.Response.Audio) {
							this.audio = 'data:audio/mp3;base64,' + result.Response.Audio
							this.base64ToBlob(this.audio)
						}

					} else {
						let msg = {
							Text: text,
							ProjectId: 1234,
							VoiceType: this.voiceList[this.voiceIndex].id,
							EmotionCategory: 'exciting'
						}
						console.log("长文本");
						//签名
						voiceSignature = await genTtsLongSignature(msg)
						createVoiceTask = await longTextToVoice(voiceSignature)
						// console.log(888888888, createVoiceTask)
						if (!createVoiceTask.Response.Data.TaskId) return

						voiceSignature = await genTtsLongSignature({
							TaskId: createVoiceTask.Response.Data.TaskId
						})
						// 轮询接收任务状态
						await this.pollTextToVoiceTaskStatus(createVoiceTask.Response.Data.TaskId,
							voiceSignature)

					}
				}
				innerAudioContext.src = this.audio
				innerAudioContext.play()

			},
			//打开选择音色弹窗
			openDialog() {
				this.$refs.popup.open('center')
			},
			//打开助理选择弹窗
			openRoleDialog() {
				this.$refs.rolePopup.open('center')
			},
			// 选择音色
			selectVoice(i) {
				this.voiceIndex = i
				this.$refs.popup.close()
			}
		},
		beforeDestroy() {
			// AsrUniModule.stopAsr()
		},
		onUnload() {
			clearTimeout(this.timeoutTimer) //清除定时器
			AsrUniModule.stopAsr() //停止录音
			if (innerAudioContext) {
				try {
					innerAudioContext.pause() //停止播放器
					// innerAudioContext = null
				} catch (e) {
					console.log(e, "erroe")
				}
			}
			plus.globalEvent.removeEventListener("asrEvent", function() {}) //移除android监听

		},
	}
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		align-items: center;
		flex-direction: column;
		padding: 10px 0;

		.con-head {
			margin: 20px 0 15px 0;
		}

		.con-tab {


			.tabBox {
				padding: 2px 5px;
			}

			.tabBoxActive {
				padding: 2px 5px;
				background-color: #413d3d;
				border-radius: 2px;
			}
		}

		.mainCon {
			display: flex;
			flex-direction: column;
			justify-content: space-evenly;
			align-items: center;
		}



		.record-animate-box {
			margin: 0 10px;
			width: 250rpx;
			border-radius: 28rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			transition: all .3s;

			/* 语音音阶 */
			.voice-scale {
				width: 100%;
				height: 60rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.item {
					display: block;
					background: #ffffff;
					width: 40rpx;
					border-radius: 10rpx;
					height: 10%;
					margin-right: 2.5px;
					float: left
				}

				.itemActive {
					display: block;
					background: #ffffff;
					width: 40rpx;
					border-radius: 10rpx;
					height: 10%;
					margin-right: 2.5px;
					float: left;

					&:last-child {
						margin-right: 0px;
					}

					&:nth-child(1) {
						animation: load 1s 0.8s infinite linear;
					}

					&:nth-child(2) {
						animation: load 1s 0.6s infinite linear;
					}

					&:nth-child(3) {
						animation: load 1s 0.4s infinite linear;
					}

					&:nth-child(4) {
						animation: load 1s 0.2s infinite linear;
					}

					&:nth-child(5) {
						animation: load 1s 0s infinite linear;
					}

					&:nth-child(6) {
						animation: load 1s 0.2s infinite linear;
					}

					&:nth-child(7) {
						animation: load 1s 0.4s infinite linear;
					}

					&:nth-child(8) {
						animation: load 1s 0.6s infinite linear;
					}

					&:nth-child(9) {
						animation: load 1s 0.8s infinite linear;
					}

					&:nth-child(10) {
						animation: load 1s 1s infinite linear;
					}
				}
			}

			@keyframes load {
				0% {
					height: 10%;
				}

				50% {
					height: 100%;
				}

				100% {
					height: 10%;
				}
			}
		}

		.callBox {
			margin: 10rpx 0;
			display: flex;
			align-items: center;

			.offBtn {
				width: 40px;
				height: 40px;
				background-color: #413d3d;
				border-radius: 50px;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.off {
				width: 13px;
				height: 13px;
				background-color: #fff;
				border-radius: 2px;
			}
		}
	}
</style>